﻿/*
   Copyright 2012 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Flower.Services.Data;
using Flower.Workflow;

namespace Flower.Processing
{
    /// <summary>
    /// Base class of all activities.
    /// </summary>
    public abstract class Activity : IActivity
    {
        public string Name { get; internal set; }
        public abstract bool IsBlocking { get; }
        public ActivityLocation Location { get; internal set; }
        internal List<ExceptionContainer> ExceptionContainers { get; private set; }

        protected Activity()
        {
            ExceptionContainers = new List<ExceptionContainer>();
        }

        public abstract Interruption Do(Processor processor);

        protected static BlobFormat Convert(MessageFormat format)
        {
            switch (format)
            {
                case MessageFormat.TextXml:
                    return BlobFormat.TextXml;
                case MessageFormat.BinXml:
                    return BlobFormat.BinXml;
                case MessageFormat.GZipXml:
                    return BlobFormat.GZipXml;
                default:
                    throw new ArgumentOutOfRangeException("format");
            }
        }
    }
}
